var url = serverPre + "/manager/scs/v2//replenish/list";

var bsConf = {

    queryFormId: "src-query-form",

    createFormId: "src-create-form",

    tableID: "id",

    queryCols: 3,

    queryFloat: "right",

    voName: "sc",
    initData: true,
    // needChangeTab: true,
    //
    // needInitECharts: true,

    queryConfigs:                   //页面头部查询form
        [
            {
                type: 'text',
                placeholder: '企业名称',
                label: '企业名称',
                name: 'sealOrg',
                default: '',
                verify: ''
            }

        ],

    //列表内容
    tableCols: [
        {field: 'id', title: '序号', type: 'numbers'}
        , {field: 'sealCode', width: 155, title: '印章编号', align: 'center'}
        , {field: 'sealName', title: '印章名称', align: 'center'}
        , {field: 'sealOrg', title: '企业名称', align: 'center'}
        , {fixed: 'right', width: 250, title: '操作', align: 'left', toolbar: '#bar'}
    ],

    bindOwnTableEventCol: function (layEvent, data) {
         if (layEvent === 'replenish') {//查看统计
             replenish(data['id']);
        }
    }
}



function query_search() {
    if ($("#up").hasClass("layui-icon-down")) {
        document.getElementById('up').classList.add("layui-icon-up");
        document.getElementById('up').classList.remove("layui-icon-down");
    } else {
        document.getElementById('up').classList.add("layui-icon-down");
        document.getElementById('up').classList.remove("layui-icon-up");

    }
    $("#product-query-form").toggle()
}

function closethis(a) {
    debugger;
    $(a).closest(".layui-layer-page").remove();
    /*var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(a);*/
}
function sealInfo(id) {
    var u = serverPre + "/manager/scs/v2/seal/channel/sealinfo/" + id;
    var response = $.ajax({
        type: "GET",
        url: u,
        headers: {"token": getCookie("token")},
        async: false,
        success: function (data) {
            debugger;
            //  alert(JSON.stringify(data)
        }
    });

    var json = response.responseJSON;

    if (json.code === 0) {
        layer.open({
            type: 1,
            title: '印章信息',
            shadeClose: true,
            shade: false,
            maxmin: true,
            content: generateHtml(json.data),
            area: ['50%', '50%'],
            success: function () {
                $(".layui-layer-setwin").hide();
            }
        });
    } else {
        layer.msg("内部错误", {
            icon: 0,
            time: 2000
        });
    }
}


/**
 * 更新公章图片
 */
function replenish(id) {
    xadmin.open("更新公章图片", "./edit.html?id="+id, 600, 800);
}

/**
 * 文件上传
 */
function uploadFile(upload, uploadUrl) {
    upload.render({
        elem: '#uploadImage'
        , url: uploadUrl
        , accept: 'images' //普通文件
        , headers: {"token": getCookie("token")}
        , size: '1024'
        , exts: "png"
        , done: function (res) {
            if (res.code === 0) {
                $('#pictureId').val(res.data.pictureId);
                $("#fileName").html(res.data.fileName)
                alert("上传成功！");
            } else {
                errorMsg("文件上传失败！")
            }
        }
    });
}

function buildEditWin(form,id) {
    var url = serverPre + "/manager/scs/v2/seal/channel/sealInfo/"+id;
    $.ajax({
        url: url,
        type: 'GET',
        contentType: 'application/json',
        headers: {'token': getCookie('token')},
        success: function (res) {
            if (res.code === 0) {
                var obj = res.data.vo;
                $("#sealOrg").val(obj.sealOrg);
                $("#identificationType").val(obj.identificationType);
                $("#identificationTypeName").val(obj.identificationTypeName);
                $("#identificationNo").val(obj.identificationNo);
                $("#sealCode").val(obj.sealCode);
                $("#sealName").val(obj.sealName);
                $("#keyWords").val(obj.keyWords);
                $("#imageCode").val(obj.ext1);
                $("#sealPwd").val(obj.sealPwd);
            }
        },
        error: function (err) {
            errorMsg(err);
        }
    });
}

/**
 * 提交表单
 * @param formData
 * @param url
 */
function submitForm(commitData, url) {
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form;
        //监听提交
        form.on('submit(submitBtn)', function (data) {
            /*if (data.field.pictureId === "") {
                alert("公章图片不能为空!");
                return false;
            }*/
            saveSealInfo(url, commitData);
            return false;
        });
    })
}

/**
 * 保存印章
 * @param url
 * @param commitData
 */
function saveSealInfo(url, commitData) {
    var loading = layer.msg('正在保存...', {icon: 16, shade: 0.3, time: 0});
    $.ajax({
        url: url,
        data: commitData,
        type: 'POST',
        contentType: 'application/json',
        headers: {'token': getCookie('token')},
        success: function (res) {
            debugger
            if (res.code === 0) {
                layer.close(loading);
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                layer.close(index);
                parent.location.reload();
            } else {
                layer.close(loading);
                alert(res.msg);
            }
        },
        error: function (err) {
            layer.close(loading);
            errorMsg(err);
        }
    });
}
